#include<iostream>
#include<string>
using namespace std;

int Haab_convert(string str);
string Tzolkin_convert(int n);

int main()
{
    int n;
	cin>>n;
	int Hday;
	string Hmonth;
	int Hyear;
	long sum_day;
	int Tnumber;
	string Tname;
	int Tyear;
	int k=0;
	cout<<n<<endl;
	while(n--)
	{
		cin>>Hday;
		cin.ignore();
		cin>>Hmonth;
		cin>>Hyear;
		sum_day=(Haab_convert(Hmonth)*20+Hday+1)+365*Hyear;
		Tyear=(sum_day%260==0&&sum_day>=260)?sum_day/260-1:sum_day/260;
		sum_day=sum_day%260;
		Tname=Tzolkin_convert(sum_day%20);
		Tnumber=sum_day%13==0?13:sum_day%13;
	    cout<<Tnumber<<" "<<Tname<<" "<<Tyear<<endl;
	}
	return 0;
}

int Haab_convert(string str)
{
	string s[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};	
	for(int i=0;i<19;i++)
	{
		if(str==s[i])
			return i;
	}
}

string Tzolkin_convert(int n)
{
	switch(n)
	{
	case 1:return "imix";
	case 2:return "ik";
	case 3:return "akbal";
	case 4:return "kan";
	case 5:return "chicchan";
	case 6:return "cimi";
	case 7:return "manik";
	case 8:return "lamat";
	case 9:return "muluk";
	case 10:return "ok";
	case 11:return "chuen";
	case 12:return "eb";
	case 13:return "ben";
	case 14:return "ix";
	case 15:return "mem";
	case 16:return "cib";
	case 17:return "caban";
	case 18:return "eznab";
	case 19:return "canac";
	case 0:return "ahau";
	}
}